<!DOCTYPE HTML>
<?php session_start();?>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<title>教师界面</title>
		<link rel="stylesheet" type="text/css" href="tstyle.css"/>
	</head>
	
	<body>
		<script type="text/javascript">
			var c=1;
			var l=1;
			var m=true;
			
			function cc(){
				
				var stu=document.getElementById("stu").style;
				
				if(c==1){
					stu.cssText="-webkit-transform:scale(1,-1);";
					c=0;
					document.getElementById("stuimg").style.display="inline";
				}
				else {
					stu.cssText="-webkit-transform:scale(1);";
					c=1;
					document.getElementById("stuimg").style.display="none";
				}
			
			}
			
			function slide(){
				
				var di=document.getElementById("decimg");
				
				if(l==0){
						m=true;
						di.style.left="0px";
				}
				else if(l==2){
						m=false;
						di.style.left="-520px";
				}
				else if(l==1){
				di.style.left="-260px";
				}
				
				if(m)
					l++;
				else
					l--;
			}
			
			function checktime(i){
				if(i<10)
					i="0"+i;
				return i;
			}
			
			function updatetime(){
				
				var date = new Date;
				
				var time = checktime(date.getHours())+":"+checktime(date.getMinutes());
				var mon = date.getMonth()+1;
				var day = date.getFullYear()+"/"+mon+"/"+date.getDate();
				
				document.getElementById("time").innerHTML=time;
				document.getElementById("date").innerHTML=day;
			}			
			
			setInterval("updatetime()",1000);
			setInterval("slide()",4000);
			setInterval("cc()",5000);
		</script>
		
		<nav>
			<ul>
				<li><a href="">Module 1</a>
					<ul> 
					  <?php 
					  //连接数据库
					    $conn;
			            include '../public/conn.php';
						$res=mysql_query("SELECT *FROM log WHERE unit_id = '1'");
					    
						while($title = mysql_fetch_array($res)){
					  ?>
						<li><a href="../log/log_read.php?id=<?php echo $title['log_id'];?>"><?php echo $title['log_title'] ?></a></li>
						 <?php
						 }?>
					</ul>
				</li>
				
				<li><a href="">Module 2</a>
					<ul>
					<?php
						$res = mysql_query("SELECT *FROM log WHERE unit_id = '2'");
			       
						while($title = mysql_fetch_array($res)){
					  ?>
						<li><a href="../log/log_read.php?id=<?php echo $title['log_id'];?>"><?php echo $title['log_title'] ?></a></li>
						<?php
						   }?>
					</ul>
				</li>
				
				<li><a href="">Module 3</a>
					<ul>
					  <?php
						$res=mysql_query("SELECT *FROM log WHERE unit_id = '3'");
						while($title = mysql_fetch_array($res)){
					  ?>
						<li><a href="../log/log_read.php?id=<?php echo $title['log_id'];?>"><?php echo $title['log_title'] ?></a></li>
					  <?php
						   }?>
					</ul>
				</li>
				
				<li><a href="">Module 4</a>
					<ul>
					  <?php
						$res=mysql_query("SELECT *FROM log WHERE unit_id = '4'");
						while($title = mysql_fetch_array($res)){
					    ?>
						<li><a href="../log/log_read.php?id=<?php echo $title['log_id'];?>"><?php echo $title['log_title'] ?></a></li>
					 <?php
						   }?>
					</ul>
				</li>
			</ul>
		</nav>	

		<div id="clock">
			<a href="../reg_login/sign.html#r"><h2>Log off</h2></a>	
			<h1 id="time"></h1>
			<h3 id="date"></h3>
		</div>
		
		<section>
			<form  method="post" action="teacher.php">

			<p>
			  Userid:
			  <input type="text" name="search"  placeholder="input log's title"  style="width:200px; height:20px"/></p>
			<input class="ins" type="submit" value="Search"/>
			</form>
		</section>
		
		
		
		<aside>
			<h1>The newest article</h1>
			<ul>				    
      			<?php

         			//判断获取的搜索值是否为空
			        if(!empty($_POST['search'])){
						$search = $_POST['search'];
					}
					else{
					    $search=NULL;
					}
		               
                    //获取session
					$strName = $_SESSION['userName'];
				    //读取最新日志
				    $search_res = mysql_query("select * from log ORDER BY log_date DESC,log_time DESC LIMIT 8" , $conn);
				    $rows = mysql_num_rows($search_res);
				    $row = mysql_fetch_array($search_res);
				
                    //循环输出用户日志
					for($i=0; $i<8; $i++){
						$title = $row['log_title'];
						$log_date = $row['log_date'];
						$log_time = $row['log_time'];
				?>
				<li><a href="../log/log_read.php?id=<?php echo $row['log_id'];?>"><?php echo ($i+1).". ".$title."------".$log_date."--".$log_time;?></a></li>
				<?php 
					$row = mysql_fetch_array($search_res);
				}
			    ?>
			</ul>
		</aside>
		
		<!--查询结果-->
		<article>
			<h1>Result:</h1>
			<ul>
				  <!--连接数据库-->
      			<?php
  				    $conn;
			        include '../public/conn.php';        
			        
         			//判断获取的搜索值是否为空
			        if(!empty($_POST['search'])){
						$search = $_POST['search'];
					}
					else{
					    $search=NULL;
					}
		               
                    //获取session
					$strName=$_SESSION['userName'];
				    
				    $search_res=mysql_query("select * from log where log_title like '%$search%'" ,$conn);
				    $row=mysql_fetch_array($search_res);
					$rows=mysql_num_rows($search_res);
					
                    //循环输出用户日志
					for($i=0; $i<1; $i++){
						$title = $row['log_title'];
						$log_date = $row['log_date'];
						$log_time = $row['log_time'];
				?>
				<li><a href="../log/log_read.php?id=<?php echo $row['log_id'] ?>">
				  <?php echo($i+1).".".$title."----------".$log_date."-".$log_time; ?></a></li>
				<?php 
					$row = mysql_fetch_array($res);
				}
			    ?>
				</ul>
		</article>
		
		<div id="stu">
			<img id="stuimg" src="infor.jpg"/>
			 
	         <?php
		      // 检查是否已设置session,显示老师姓名
	            if(isset($_SESSION['userName'])) {
	            echo "<h2>Hello！<span>".$_SESSION['userName']."</span> </h2>";
		       }
		       else {
	             echo "<script>";
	             echo "alert('You are not logged, please login.');";
	             echo "location.href = '../reg_login/sign.html';";
	             echo "</script>";	
	           }
	         ?>
			
			<h5>Num of comments<span>12</span></h5>
			
		</div>
	</body>	
	</html>